import re
with open("role_match.txt",'r',encoding='utf-8') as file:
    content = file.readlines()
# predicate = {"SBJ":'Datv', 'OBJ':'Pat'}
predicate = {}
sbj, obj = [], []
word = ""
for line in content:
    if line[0] == '@':
        if word != "":
            if len(sbj) !=0 and len(obj) != 0:
                predicate[word] = {"sbj":sbj[0], 'obj':obj[0]}
            if len(sbj) !=0 and len(obj) == 0:
                predicate[word] = {"sbj":sbj[0]}
            if len(sbj) ==0 and len(obj) != 0:
                predicate[word] = {'obj':obj[0]}
        sbj, obj = [], []
        word = line.strip()[1:-3]
    else:
        if len(line.strip().split()) == 3:
            if line.strip().split()[-1] == 'sbj':
                sbj.append(line.strip().split()[0])
            if line.strip().split()[-1] == 'obj':
                obj.append(line.strip().split()[0])
        
# print(predicate)
time = {'Tini':'Time','Tfin':'Time','TDur':'Time','Trang':'Time'}
loc = {'Lini':'Loc','Lfin':'Loc','Lthru':'Loc'}

# with open("out.txt",'r',encoding='utf-8') as file:
#     content = file.readlines()
# triple = {}
# for i in range(len(content)):
#     if content[i].strip()[0] == '@':
#         key = re.split("([A-Z]+)",content[i].strip()[1:])[0]
#     elif content[i].strip()[0] == '#':
#         rel = content[i].strip()[1:]
#         if rel in time:
#             rel = time.get(rel,rel)
#         if rel in loc:
#             rel = loc.get(rel,rel)
#     else:
#         if rel[0] not in ['m','d','r','e']:
#             word = content[i].strip().split()[0]
#             triple.setdefault(key + '_' + word,set()).add(rel)
# print(triple)

# verb = {}
# with open('arg.txt','r',encoding = 'utf-8') as file:
#     for line in file:
#         head = line.strip().split()
#         if len(head) == 3:
#              verb[head[0]] = {"sbj":head[1], 'obj':head[2]}
#         if len(head) == 2:
#              verb[head[0]] = {"sbj":head[1]}
       
        
# print(verb)

with open('out6.txt','r',encoding='utf-8') as file:
    content = file.readlines()
triple = {}
for i in range(len(content)):
    if content[i].strip()[0] == '@':
        key = re.split("([A-Z]+)",content[i].strip()[1:])[0]
    elif content[i].strip()[0] == '#':
        rel = content[i].strip()[1:]
        if rel in time:
            rel = time.get(rel,rel)
        if rel in loc:
            rel = loc.get(rel,rel)
        if rel == 'Sproc':
            rel = "Stat"
    else:
        if rel[0] not in ['m','d','r','e'] and rel not in ['Host','Nmod','Int','Seq','Tmod','Desc']:  # 去掉这几个角色
            word = content[i].strip().split()[0]
            triple.setdefault(key + '_' + word,set()).add(rel)
print(triple)